package com.example.ywj.myapplication.weixin2;

import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.widget.RadioGroup;

import com.example.ywj.myapplication.R;
import com.example.ywj.myapplication.weixin.ContactFragment;
import com.example.ywj.myapplication.weixin.FindFragment;
import com.example.ywj.myapplication.weixin.UserFragment;
import com.example.ywj.myapplication.weixin.WeiXinFragment;

import java.util.ArrayList;

public class HomeActivity extends AppCompatActivity {
    ViewPager vp ;
    private ArrayList<Fragment> list = new ArrayList<>();
    RadioGroup radiogroup;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        vp = findViewById(R.id.vp_fragment);
        radiogroup = findViewById(R.id.radiogroup);
        WeiXinFragment weiXinFragment = new WeiXinFragment();
        FindFragment findFragment = new FindFragment();
        UserFragment userFragment = new UserFragment();
        ContactFragment contactFragment = new ContactFragment();
        list.add(weiXinFragment);
        list.add(findFragment);
        list.add(userFragment);
        list.add(contactFragment);
        MyFragmentPagerAdapter myFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(),list);
        vp.setAdapter(myFragmentPagerAdapter);
        radiogroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.radio0:
                        vp.setCurrentItem(0);
                        break;
                    case R.id.radio1:
                        vp.setCurrentItem(1);
                        break;
                    case R.id.radio2:
                        vp.setCurrentItem(2);
                        break;
                    case R.id.radio3:
                        vp.setCurrentItem(3);
                        break;
                }
            }
        });
    }
}
